#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

#include "binfile.h"
#include "both.h"


Int64 fCount, f;
Int8 fLen, n, fComp;
vector<bool> MarkArray;

BinFile writer, reader;

inline void MarkClassBy(const Int64 f) {
  Int64 fTmp = f;
  for(Int8 i = 0; i < Shift.size(); i++) {
    if (i != 0) fTmp = swapvars(fTmp, Shift[i], n);    
    Int64 fTmp2 = fTmp, fTmp21 = fTmp, fTmp22 = fTmp, fTmp23 = fTmp, fTmp24 = fTmp;
    for(Int8 j = 0; j < Gray.size(); j++) {
      if (j != 0) {
        fTmp2 = negbyvar(fTmp2, Gray[j], n);
        fTmp21 = d1byvar(fTmp21, Gray[j], n);        
        fTmp22 = d2byvar(fTmp22, Gray[j], n);
        fTmp23 = d3byvar(fTmp23, Gray[j], n);
        fTmp24 = d4byvar(fTmp24, Gray[j], n);                
        MarkArray[fTmp21] = true;
        MarkArray[fTmp22] = true;
        MarkArray[fTmp23] = true;
        MarkArray[fTmp24] = true;        
      }
      MarkArray[fTmp2] = true;
    }    
  }
}


inline void LoadInfo() {  
  ostringstream oss;
  fLen = 1 << n;
  fCount = (Int64)1 << fLen;
  MarkArray.resize(fCount);
  
  oss << "binfile" << (int)n << 'v' << (int)fComp << "r.mbf";
  reader.open(oss.str(), BIN_FILE_READ);
  
  MakeAddArrays(n);
  
  oss.str("");
  oss << "binfile" << (int)n << "vf" << (int)fComp << "r.mbf";
  writer.open(oss.str(), BIN_FILE_WRITE);  
}
/*
9
*/

int main () {
  n = 5;
  cin >> (int&)fComp;
  
  LoadInfo();
  
  while(true) {
    reader.read((Int32&)f);
    MarkClassBy(f);
    if (reader.isEnd()) break;
  }
  
  for(size_t i = 0; i < MarkArray.size(); i++) {
    if (MarkArray[i]) writer.write((Int32)i);
  }
    
  return 0;
}
